package com.sky.mapper;

import com.sky.anno.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {

    @AutoFill(OperationType.INSERT)
    @Insert("insert into dish(name,category_id,price,image,description,status,create_time,update_time,create_user,update_user) " +
            "values(#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser}) ")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void adddish(Dish dish);

    @Insert("insert into dish_flavor(name,value,dish_id) values(#{name},#{value},#{dishId})")
    void addFlavor(DishFlavor flavors);


    @AutoFill(OperationType.UPDATE)
    void editDish(Dish dish);

    @Delete("delete from dish where id = #{id}")
    void deleteDish(long id);

    @Delete("delete from dish_flavor where dish_id = (#{id})")
    void deleteFlavor(Long id);

    @Select("select * from dish where id = #{id}")
    Dish list(Long id);

    @Select("select * from dish_flavor where dish_id = #{id}")
    List<DishFlavor> selectlistFlavor(Long id);

    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> selectDishByCategoryId(Long categoryId);

    List<DishVO> selectByPage(DishPageQueryDTO dishDTO);

    @Update("update dish set status = #{status} where id = #{id}")
    void editStatus(Long id, Integer status);

    @Select("select status from dish where id = #{id}")
    Integer selectStatus(Long id);

    @Select("select count(*) from setmeal_dish where dish_id = #{id}")
    Integer selectSetmealByDishId(Long id);
}
